package com.fintech.third.service.bairong;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.fintech.common.enums.RespStatus;
import com.fintech.common.service.BaseServiceImpl;
import com.fintech.common.util.ApiResponse;
import com.fintech.common.util.PropertiesUtils;
import com.fintech.datagroud.dao.bairong.EdcBrSignequipmentMapper;
import com.fintech.datagroud.dao.bairong.IntBrRegisterEquipmentMapper;
import com.fintech.datagroud.entity.bairong.EdcBrRuleResult;
import com.fintech.datagroud.entity.bairong.EdcBrRuleResultDetail;
import com.fintech.datagroud.service.DGBaiRongService;
import com.fintech.third.constant.LocalStatus;
import com.fintech.third.constant.ThirdMethodConstants;
import com.fintech.third.constant.ThirdProductChannelConstant;
import com.fintech.third.dao.EdcBrRuleFlagSignMapper;
import com.fintech.third.model.EquipmentInfor;
import com.fintech.third.model.ThirdProperties;
import com.fintech.third.model.bairong.ApplicationInfoAssociate;
import com.fintech.third.model.bairong.CurrentEquipmentInformationReport;
import com.fintech.third.model.bairong.CurrentEquipmentPackageInfo;
import com.fintech.third.model.bairong.EdcBrRuleFlagSign;
import com.fintech.third.model.bairong.EquipmentInfo;
import com.fintech.third.model.bairong.EquipmentSpecialList;
import com.fintech.third.model.bairong.IncomeMonthLevel;
import com.fintech.third.model.bairong.LoanFacilityInformation;
import com.fintech.third.model.bairong.LoanFacilityPackageInfo;
import com.fintech.third.model.bairong.LoginFacilityInformation;
import com.fintech.third.model.bairong.LoginFacilityPackageInfo;
import com.fintech.third.model.bairong.MultipleApplications;
import com.fintech.third.model.bairong.OccApplyLoanInfo;
import com.fintech.third.model.bairong.OccRuleInformation;
import com.fintech.third.model.bairong.OccScoreInfo;
import com.fintech.third.model.bairong.PaymentConsum;
import com.fintech.third.model.bairong.RegisterFacilityInformation;
import com.fintech.third.model.bairong.RegisterFacilityPackageInfo;
import com.fintech.third.model.bairong.Score;
import com.fintech.third.model.bairong.SpecialList;
import com.fintech.third.model.bairong.Stability;
import com.fintech.third.model.bairong.XssPackAllInterfaceInfo;
import com.fintech.third.utils.ThirdPropertiesInitUtil;
import com.fintech.third.utils.bairong.BaiRongUtil;
import com.marvels.common.utils.MarvelsLogUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service("OneCreditCard")
public class OneCreditCardImpl extends BaseServiceImpl implements OneCreditCardService {

	@Autowired
	private DGBaiRongService dGBaiRongService;

	@Autowired
	private EdcBrSignequipmentMapper edcBrSignequipmentMapper;

	@Autowired
	private IntBrRegisterEquipmentMapper intBrRegisterEquipmentMapper;

	@Autowired
	private EdcBrRuleFlagSignMapper edcBrRuleFlagSignMapper;

	/**
	 * 登陆百融方法
	 * 
	 * @return tokenId 任务Id
	 */
	public String platLogin() {
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		JSONObject json = new JSONObject();
		json.put("userName", thirdProperties.getBr_oneCreditCard_merchantName());
		json.put("password", thirdProperties.getBr_oneCreditCard_merchantPwd());
		json.put("apiCode", thirdProperties.getBr_oneCreditCard_apiCode());
		String result = "";
		String tokenId = "";
		try {
			result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_loginRequestUrl(),
					"userName=" + thirdProperties.getBr_oneCreditCard_merchantName() + "&password="
							+ thirdProperties.getBr_oneCreditCard_merchantPwd() + "&apiCode="
							+ thirdProperties.getBr_oneCreditCard_apiCode());
		} catch (Exception e) {

			e.printStackTrace();
		}

		if (StringUtils.isNotEmpty(result)) {
			MarvelsLogUtil.getInstance().info("平台登录百融返回信息:" + result);
			JSONObject resultJson = new JSONObject();
			resultJson = JSONObject.fromObject(result);
			if (resultJson.get("code").toString().equals("00")) {
				tokenId = resultJson.get("tokenid").toString();
			}
		}
		return tokenId;
	}

	public ApiResponse<OccRuleInformation> occRuleReport(JSONObject json, String serialNum, String loanId,
			String channel) {
		ApiResponse<OccRuleInformation> resp = new ApiResponse<OccRuleInformation>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0040")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = LocalStatus.REQUEST_FAIL.getCode(); // 默认请求失败
		String thirdCode = null;
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		Date sTime = new Date();
		OccRuleInformation occRuleInformation = new OccRuleInformation();
		String tokenId = platLogin();
		String result = "";
		String method = ThirdMethodConstants.BR0040;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));

			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error("获取百融规则报告异常",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
			if (StringUtils.isNotEmpty(result)) {

				MarvelsLogUtil.getInstance().info("获取百融规则报告返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				String code = resultJson.get("code").toString();
				thirdCode = code;
				if (code.equals("100002")) {

					resp.setCode(RespStatus.NODATA.getCode());
					resp.setMsg(RespStatus.NODATA.getMsg());
					status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode(); // 成功无数据
				} else if (code.equals("00")) {
					occRuleInformation = JSON.parseObject(result, OccRuleInformation.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(occRuleInformation);
					status = LocalStatus.SUCCESS_WITH_DATA.getCode(); // 成功有数据
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", occRuleInformation.getSwift_number(), sTime, ThirdMethodConstants.BR0040,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<SpecialList> occSpecialListReport(JSONObject json, String serialNum, String loanId,
			String channel) {
		ApiResponse<SpecialList> resp = new ApiResponse<SpecialList>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0041")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = LocalStatus.REQUEST_FAIL.getCode(); // 默认请求失败
		String thirdCode = null;
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		Date sTime = new Date();
		String tokenId = platLogin();
		SpecialList specialList = new SpecialList();
		String result = "";
		String method = ThirdMethodConstants.BR0041;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error("获取特殊名单核查报告异常",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}

			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info("获取特殊名单核查报告返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				String code = resultJson.get("code").toString();
				thirdCode = code;
				if (code.equals("100002")) {

					resp.setCode(RespStatus.NODATA.getCode());
					resp.setMsg(RespStatus.NODATA.getMsg());
					status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode(); // 成功无数据
				} else if (code.equals("00")) {
					specialList = JSON.parseObject(result, SpecialList.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(specialList);
					status = LocalStatus.SUCCESS_WITH_DATA.getCode(); // 成功有数据
				} else {
					status = LocalStatus.CALL_SUCCESS.getCode();
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", specialList.getSwift_number(), sTime, ThirdMethodConstants.BR0041,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<OccApplyLoanInfo> occApplyLoan(JSONObject json, String serialNum, String loanId,
			String channel) {
		ApiResponse<OccApplyLoanInfo> resp = new ApiResponse<OccApplyLoanInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0042")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = LocalStatus.REQUEST_FAIL.getCode(); // 默认请求失败
		String thirdCode = null;
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		OccApplyLoanInfo occApplyLoanInfo = new OccApplyLoanInfo();
		Date sTime = new Date();
		String tokenId = platLogin();
		String result = "";
		String method = ThirdMethodConstants.BR0042;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error("获取用户多次申请核查报告异常",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}

			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info("获取用户多次申请核查报告返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				String code = resultJson.get("code").toString();
				thirdCode = code;
				if (code.equals("100002")) {

					resp.setCode(RespStatus.NODATA.getCode());
					resp.setMsg(RespStatus.NODATA.getMsg());
					status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode(); // 成功无数据
				} else if (code.equals("00")) {
					occApplyLoanInfo = JSON.parseObject(result, OccApplyLoanInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(occApplyLoanInfo);
					status = LocalStatus.SUCCESS_WITH_DATA.getCode(); // 成功有数据
				} else {
					status = LocalStatus.CALL_SUCCESS.getCode();
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", occApplyLoanInfo.getSwift_number(), sTime, ThirdMethodConstants.BR0042,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<Stability> occTabilityReport(JSONObject json, String serialNum, String loanId, String channel) {
		ApiResponse<Stability> resp = new ApiResponse<Stability>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0043")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = ""; // 默认请求失败
		String thirdCode = null;
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		Date sTime = new Date();
		Stability stability = new Stability();
		String tokenId = platLogin();
		String result = LocalStatus.REQUEST_FAIL.getCode();
		String method = ThirdMethodConstants.BR0043;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (UnsupportedEncodingException e) {
				MarvelsLogUtil.getInstance().error("获取稳定性评估报告异常",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				e.printStackTrace();
			}

			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info("获取稳定性评估报告返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				String code = resultJson.get("code").toString();
				thirdCode = code;
				if (code.equals("100002")) {

					resp.setCode(RespStatus.NODATA.getCode());
					resp.setMsg(RespStatus.NODATA.getMsg());
					status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode(); // 成功无数据
				} else if (code.equals("00")) {
					stability = JSON.parseObject(result, Stability.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(stability);
					status = LocalStatus.SUCCESS_WITH_DATA.getCode(); // 成功有数据
				} else {
					status = LocalStatus.CALL_SUCCESS.getCode();
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", stability.getSwift_number(), sTime, ThirdMethodConstants.BR0043,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<IncomeMonthLevel> occAccountchangeMonthReport(JSONObject json, String serialNum, String loanId,
			String channel) {
		ApiResponse<IncomeMonthLevel> resp = new ApiResponse<IncomeMonthLevel>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0044")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = LocalStatus.REQUEST_FAIL.getCode(); // 默认请求失败
		String thirdCode = null;
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		IncomeMonthLevel incomeMonthLevel = new IncomeMonthLevel();
		Date sTime = new Date();
		String tokenId = platLogin();
		String result = "";
		String method = ThirdMethodConstants.BR0044;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (UnsupportedEncodingException e) {
				MarvelsLogUtil.getInstance().error("获取月度收支报告异常",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}

			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info("获取月度收支报告返回信息:" + result);

				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				String code = resultJson.get("code").toString();
				thirdCode = code;
				if (code.equals("100002")) {

					resp.setCode(RespStatus.NODATA.getCode());
					resp.setMsg(RespStatus.NODATA.getMsg());
					status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode(); // 成功无数据
				} else if (code.equals("00")) {
					incomeMonthLevel = JSON.parseObject(result, IncomeMonthLevel.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(incomeMonthLevel);
					status = LocalStatus.SUCCESS_WITH_DATA.getCode(); // 成功有数据
				} else {
					status = LocalStatus.CALL_SUCCESS.getCode(); // 成功有数据
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", incomeMonthLevel.getSwift_number(), sTime, ThirdMethodConstants.BR0044,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<PaymentConsum> occPaymentConsumReport(JSONObject json, String serialNum, String loanId,
			String channel) {
		ApiResponse<PaymentConsum> resp = new ApiResponse<PaymentConsum>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0045")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = LocalStatus.REQUEST_FAIL.getCode(); // 默认请求失败
		String thirdCode = null;
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		PaymentConsum paymentConsum = new PaymentConsum();
		Date sTime = new Date();
		String tokenId = platLogin();
		String result = "";
		String method = ThirdMethodConstants.BR0045;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (UnsupportedEncodingException e) {
				MarvelsLogUtil.getInstance().error("百融occPaymentConsumReport方法异常",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}

			if (StringUtils.isNotEmpty(result)) {
				status = LocalStatus.SUCCESS_WITH_DATA.getCode(); 
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", paymentConsum.getSwift_number(), sTime, ThirdMethodConstants.BR0045,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<OccScoreInfo> occScoreReport(JSONObject json, String serialNum, String loanId, String channel) {
		ApiResponse<OccScoreInfo> resp = new ApiResponse<OccScoreInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0046")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String status = LocalStatus.REQUEST_FAIL.getCode(); // 默认请求失败
		String thirdCode = null;
		Date sTime = new Date();
		OccScoreInfo occScoreInfo = new OccScoreInfo();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		String tokenId = platLogin();
		String result = "";
		String method = ThirdMethodConstants.BR0046;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (UnsupportedEncodingException e) {
				MarvelsLogUtil.getInstance().error("获取非银小额线上现金贷客群评分",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}

			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info("获取非银小额线上现金贷客群评分返回信息:" + result);
				occScoreInfo = JSON.parseObject(result, OccScoreInfo.class);
				resp.setCode(RespStatus.SUCCESS.getCode());
				resp.setMsg(RespStatus.SUCCESS.getMsg());
				resp.setData(occScoreInfo);
				status = LocalStatus.SUCCESS_WITH_DATA.getCode(); // 成功有数据
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", occScoreInfo.getSwift_number(), sTime, ThirdMethodConstants.BR0046,
				thirdCode, status, "edc_br_data_query_log", "");
		return resp;
	}

	public ApiResponse<LoanFacilityInformation> loanFacilityInformationReport(JSONObject json, String serialNum,
			String loanId, String channel) {
		ApiResponse<LoanFacilityInformation> resp = new ApiResponse<LoanFacilityInformation>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0002")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		String mobile = JSONArray.fromObject(json.get("cell")).getString(0);
		String tokenId = platLogin();
		Date sTime = new Date();
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		LoanFacilityInformation loanFacilityInformation = new LoanFacilityInformation();
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_apiCode() + "&jsonData="
								+ URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(), thirdProperties.getBr_apiCode(), tokenId));
				// result =
				// BaiRongUtil.urlConnectPost("https://sandbox-api.100credit.cn/bankServer2/data/terData.action",
				// "tokenid=" + tokenId + "&apiCode=" +
				// thirdProperties.getBr_apiCode() + "&jsonData="
				// + URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
				// + BaiRongUtil.getCheckData(json.toString(),
				// thirdProperties.getBr_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().info(e.getMessage());
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
				MarvelsLogUtil.getInstance().error(">>>>>>>百融一卡贷借款设备请求异常:",e);
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>百融一卡贷借款设备返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					loanFacilityInformation = JSON.parseObject(result, LoanFacilityInformation.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(loanFacilityInformation);
					// 数据落地
					try {
						dGBaiRongService.loanFacilityInformationReport(loanFacilityInformation, serialNum, loanId,
								mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error("百融一卡贷借款设备数据落地失败：" + e.getMessage());
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
					ThirdMethodConstants.YK0002, sTime, eTime);
		}
		
		saveDataQueryLog(serialNum, loanId, "", loanFacilityInformation.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0002,
				code, status, "edc_br_data_query_log", "sys");
		
		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
				ThirdMethodConstants.YK0002, sTime, eTime, loanFacilityInformation.getSwift_number(), "");

		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(loanId, ThirdMethodConstants.YK0002, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷借款设备信息");
		return resp;
	}

	public ApiResponse<LoginFacilityInformation> loginFacilityInformationReport(JSONObject json, String serialNum,
			String loanId, String channel) {
		ApiResponse<LoginFacilityInformation> resp = new ApiResponse<LoginFacilityInformation>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0004")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		Date sTime = new Date();
		String mobile = JSONArray.fromObject(json.get("cell")).getString(0);
		LoginFacilityInformation loginFacilityInformation = new LoginFacilityInformation();
		serialNum = serialNum + mobile;
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			MarvelsLogUtil.getInstance().info(">>>>>>>>>>百融一卡贷登录设备信息请求信息:" + json.toString());
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_apiCode() + "&jsonData="
								+ URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(), thirdProperties.getBr_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>百融一卡贷登录设备信息请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>百融一卡贷登录设备信息返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					loginFacilityInformation = JSON.parseObject(result, LoginFacilityInformation.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(loginFacilityInformation);
					// 数据落地
					try {
						dGBaiRongService.loginFacilityInformationReport(loginFacilityInformation, serialNum, loanId,
								mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error("百融一卡贷登录设备信息数据落地失败：" ,e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
					ThirdMethodConstants.YK0004, sTime, eTime);
		}

		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
				ThirdMethodConstants.YK0004, sTime, eTime, loginFacilityInformation.getSwift_number(), "");

		saveDataQueryLog(serialNum, loanId, "", loginFacilityInformation.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0004,
				code, status, "edc_br_data_query_log", "sys");
		
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(loanId, ThirdMethodConstants.YK0004, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷登录设备信息");
		return resp;
	}

	public ApiResponse<CurrentEquipmentInformationReport> cashFacilityInformationReport(JSONObject json,
			String serialNum, String loanId, String channel) {
		ApiResponse<CurrentEquipmentInformationReport> resp = new ApiResponse<CurrentEquipmentInformationReport>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0005")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		String tokenId = platLogin();
		String mobile = JSONArray.fromObject(json.get("cell")).getString(0);
		Date sTime = new Date();
		CurrentEquipmentInformationReport currentEquipmentInformationReport = new CurrentEquipmentInformationReport();
		serialNum = serialNum + mobile;
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_apiCode() + "&jsonData="
								+ URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(), thirdProperties.getBr_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>百融一卡贷提现设备信息请求异常：" + e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>百融一卡贷提现设备信息返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					currentEquipmentInformationReport = JSON.parseObject(result,
							CurrentEquipmentInformationReport.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(currentEquipmentInformationReport);
					// 数据落地
					try {
						dGBaiRongService.cashFacilityInformationReport(currentEquipmentInformationReport, serialNum,
								loanId, mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>>百融一卡贷提现设备信息数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
					ThirdMethodConstants.YK0005, sTime, eTime);
		}
		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
				ThirdMethodConstants.YK0005, sTime, eTime, currentEquipmentInformationReport.getSwift_number(), "");

		saveDataQueryLog(serialNum, loanId, "", currentEquipmentInformationReport.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0005,
				code, status, "edc_br_data_query_log", "sys");
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(loanId, ThirdMethodConstants.YK0005, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷提现设备信息");
		return resp;
	}

	public ApiResponse<RegisterFacilityInformation> registerFacilityInformationReport(JSONObject json, String serialNum,
			String loanId, String channel) {
		ApiResponse<RegisterFacilityInformation> resp = new ApiResponse<RegisterFacilityInformation>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0003")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		String mobile = JSONArray.fromObject(json.get("cell")).getString(0);
		String tokenId = platLogin();
		String result = "";
		String code="";
		String status="";
		Date responseDate=null;
		Date sTime = new Date();
		serialNum = serialNum + mobile;
		RegisterFacilityInformation registerFacilityInformation = new RegisterFacilityInformation();
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_apiCode() + "&jsonData="
								+ URLEncoder.encode(json.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(json.toString(), thirdProperties.getBr_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>百融一卡贷注册设备信息请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>百融一卡贷注册设备信息返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					registerFacilityInformation = JSON.parseObject(result, RegisterFacilityInformation.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(registerFacilityInformation);
					// 数据落地
					try {
						dGBaiRongService.registerFacilityInformationReport(registerFacilityInformation, serialNum,
								loanId, mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.REQUEST_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.IN_DATABASE_FAIL.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.CALL_SUCCESS.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
					ThirdMethodConstants.YK0003, sTime, eTime);
		}
		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
				ThirdMethodConstants.YK0003, sTime, eTime, registerFacilityInformation.getSwift_number(), "");

		saveDataQueryLog(serialNum, loanId, "", registerFacilityInformation.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0003,
				code, status, "edc_br_data_query_log", "sys");
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(loanId, ThirdMethodConstants.YK0003, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷注册设备信息");
		return resp;
	}


	public ApiResponse packAllInterfaceInfo(JSONObject json, String serialNum, String loanId, String channel) {
		ApiResponse<XssPackAllInterfaceInfo> resp = new ApiResponse<XssPackAllInterfaceInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0001")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		JSONObject multipleJson = new JSONObject();
		String productType = json.optString("productType");
		Date sTime = new Date();
		String meal = "";
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		if (productType.equals("2")) {// 喜刷刷
			meal = thirdProperties.getBr_xss_interface_product_code();
		} else {// 其他线下产品
			meal = thirdProperties.getBr_other_interface_product_code();
		}
		multipleJson.put("meal", meal);
		multipleJson.put("id", json.get("idNumber"));
		JSONArray array = new JSONArray();
		array.add(json.get("mobile"));
		multipleJson.put("cell", array.toString());
		multipleJson.put("name", json.get("name"));
		multipleJson.put("bank_id", json.get("bankId"));
		MarvelsLogUtil.getInstance().info("==============loanId:" + loanId + ",百融一卡贷打包所有接口请求参数:" + multipleJson.toString());
		XssPackAllInterfaceInfo xssPackAllInterfaceInfo = new XssPackAllInterfaceInfo();
		String tokenId = platLogin();
		String result = "";
		String swift_number = "";
		String code="";
		Date responseDate=null;
		String status="";
		String method = ThirdMethodConstants.YK0001;
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));

			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>百融一卡贷打包所有接口请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info("==========loanId:" + loanId + ",获取百融一卡贷打包所有接口返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					xssPackAllInterfaceInfo = JSON.parseObject(result, XssPackAllInterfaceInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(xssPackAllInterfaceInfo);
					PaymentConsum paymentConsum = null;
					if (meal.contains("PayConsumption")) {
						paymentConsum = xssPackAllInterfaceInfo.getPaymentConsumData();
					}

					SpecialList specialList = null;
					if (meal.contains("SpecialList_c")) {
						specialList = xssPackAllInterfaceInfo.getSpecialListData();
					}

					MultipleApplications multipleApplications = null;
					if (meal.contains("ApplyLoanStr")) {
						multipleApplications = xssPackAllInterfaceInfo.getMultipleApplicationsData();
					}

					/** 非银消费贷线下评分V2.0 **/
					Score score = null;
					if (meal.contains("scorepettycashv1")) {
						score = xssPackAllInterfaceInfo.getScoreData();
					}

					ApplicationInfoAssociate applicationInfoAssociate = null;
					if (meal.contains("InfoRelation")) {
						applicationInfoAssociate = xssPackAllInterfaceInfo.getApplicationInfoAssociate();
					}
					// 数据落地
					try {
						/** 支付消费评估 **/
						if (meal.contains("PayConsumption")) {
							dGBaiRongService.occPaymentConsumReport(paymentConsum, serialNum, loanId);
						}
						if (meal.contains("ApplyLoanStr")) {
							dGBaiRongService.multipleApplicationsReport(multipleApplications, serialNum, loanId);
						}

						/** 非银消费贷线下评分V2.0 **/
						if (meal.contains("scorepettycashv1")) {
							dGBaiRongService.scoreReport(score, serialNum, loanId);
						}

						/** 申请信息关联 */
						if (meal.contains("InfoRelation")) {
							dGBaiRongService.applicationInfoAssociate(applicationInfoAssociate, serialNum, loanId);
						}

						/** 特殊名单规则 **/
						if (meal.contains("SpecialList_c")) {
							dGBaiRongService.specialListReport(specialList, serialNum, loanId);
						}

						EdcBrRuleResult edcBrRuleResult = new EdcBrRuleResult();
						edcBrRuleResult.setCreatedBy("sys");
						edcBrRuleResult.setSerialNum(serialNum);
						edcBrRuleResult.setCreatedDate(new Date());
						edcBrRuleResult.setCustIdNumber(json.get("idNumber").toString());
						edcBrRuleResult.setLoanId(loanId);
						edcBrRuleResult.setRuleFinalDecision(xssPackAllInterfaceInfo.getRule_final_decision());
						edcBrRuleResult.setRuleFinalWeight(xssPackAllInterfaceInfo.getRule_final_weight());
						edcBrRuleResult.setUpdatedBy("sys");
						edcBrRuleResult.setUpdatedDate(new Date());

						/** 百融规则结果 **/
						long resultId = dGBaiRongService.ruleResult(edcBrRuleResult);

						JSONObject strJson = JSONObject.fromObject(result);
						Iterator ite = strJson.keys();
						List<EdcBrRuleResultDetail> list = new ArrayList<EdcBrRuleResultDetail>();
						EdcBrRuleFlagSign edcBrRuleFlagSignDto = new EdcBrRuleFlagSign();
						while (ite.hasNext()) {
							String key = (String) ite.next();
							String value = strJson.getString(key);
							if (key.contains("Rule_name") || key.contains("Rule_weight")) {
								EdcBrRuleResultDetail edcBrRuleResultDetail = new EdcBrRuleResultDetail();
								edcBrRuleResultDetail.setCreatedBy("sys");
								edcBrRuleResultDetail.setCreatedDate(new Date());
								String ruleCode = "";
								if (key.contains("Rule_name_")) {
									ruleCode = key.split("Rule_name_")[1];
								} else {
									ruleCode = key.split("Rule_weight_")[1];
								}
								edcBrRuleResultDetail.setRuleCode(ruleCode);
								edcBrRuleResultDetail.setKey(key);
								edcBrRuleResultDetail.setValue(value);
								edcBrRuleResultDetail.setUpdatedBy("sys");
								edcBrRuleResultDetail.setRuleResultId(String.valueOf(resultId));
								edcBrRuleResultDetail.setUpdatedDate(new Date());
								list.add(edcBrRuleResultDetail);
							}

							if (key.equalsIgnoreCase("flag_rulespeciallist")) {
								edcBrRuleFlagSignDto.setFlagRulespeciallist(value);
							}
							if (key.equalsIgnoreCase("flag_ruleapplyloan")) {
								edcBrRuleFlagSignDto.setFlagRuleapplyloan(value);
							}
							if (key.equalsIgnoreCase("flag_rulespeciallist_bank")) {
								edcBrRuleFlagSignDto.setFlagRulespeciallistBank(value);
							}
							if (key.equalsIgnoreCase("flag_ruleapplyloan_bank")) {
								edcBrRuleFlagSignDto.setFlagRuleapplyloanBank(value);
							}
							if (key.equalsIgnoreCase("flag_ruleaccountchange")) {
								edcBrRuleFlagSignDto.setFlagRuleaccountchange(value);
							}
							if (key.equalsIgnoreCase("flag_ruleaccountchange_bank")) {
								edcBrRuleFlagSignDto.setFlagRuleaccountchangeBank(value);
							}
							if (key.equalsIgnoreCase("flag_ruleaccountchange_c")) {
								edcBrRuleFlagSignDto.setFlagRuleaccountchangeC(value);
							}
							if (key.equalsIgnoreCase("flag_ruleaccountchange_c_bank")) {
								edcBrRuleFlagSignDto.setFlagRuleaccountchangeCBank(value);
							}
							if (key.equalsIgnoreCase("flag_ruleaccountchange_u")) {
								edcBrRuleFlagSignDto.setFlagRuleaccountchangeU(value);
							}
							if (key.equalsIgnoreCase("flag_ruleaccountchange_u_bank")) {
								edcBrRuleFlagSignDto.setFlagRuleaccountchangeUBank(value);
							}
							if (key.equalsIgnoreCase("flag_ruleexecution")) {
								edcBrRuleFlagSignDto.setFlagRuleexecution(value);
							}
							if (key.equalsIgnoreCase("flag_rulescore")) {
								edcBrRuleFlagSignDto.setFlagRulescore(value);
							}
							if (key.equalsIgnoreCase("flag_ruleequipmencheck")) {
								edcBrRuleFlagSignDto.setFlagRuleequipmencheck(value);
							}
							if (key.equalsIgnoreCase("flag_ruleloan_web")) {
								edcBrRuleFlagSignDto.setFlagRuleloanWeb(value);
							}
							if (key.equalsIgnoreCase("flag_ruleloan_android")) {
								edcBrRuleFlagSignDto.setFlagRuleloanAndroid(value);
							}
							if (key.equalsIgnoreCase("flag_ruleloan_ios")) {
								edcBrRuleFlagSignDto.setFlagRuleloanIos(value);
							}
							if (key.equalsIgnoreCase("flag_ruleregister_web")) {
								edcBrRuleFlagSignDto.setFlagRuleregisterWeb(value);
							}

							if (key.equalsIgnoreCase("flag_ruleregister_android")) {
								edcBrRuleFlagSignDto.setFlagRuleregisterAndroid(value);
							}

							if (key.equalsIgnoreCase("flag_ruleregister_ios")) {
								edcBrRuleFlagSignDto.setFlagRuleregisterIos(value);
							}

							if (key.equalsIgnoreCase("flag_rulelog_web")) {
								edcBrRuleFlagSignDto.setFlagRulelogWeb(value);
							}

							if (key.equalsIgnoreCase("flag_rulelog_android")) {
								edcBrRuleFlagSignDto.setFlagRulelogAndroid(value);
							}

							if (key.equalsIgnoreCase("flag_rulelog_ios")) {
								edcBrRuleFlagSignDto.setFlagRulelogIos(value);
							}

							if (key.equalsIgnoreCase("flag_rulecash_web")) {
								edcBrRuleFlagSignDto.setFlagRulecashWeb(value);
							}

							if (key.equalsIgnoreCase("flag_rulecash_android")) {
								edcBrRuleFlagSignDto.setFlagRulecashAndroid(value);
							}

							if (key.equalsIgnoreCase("flag_rulecash_ios")) {
								edcBrRuleFlagSignDto.setFlagRulecashIos(value);
							}

							if (key.equalsIgnoreCase("flag_ruleequipmentspeciallist")) {
								edcBrRuleFlagSignDto.setFlagRuleequipmentspeciallist(value);
							}
							edcBrRuleFlagSignDto.setRuleResultId(String.valueOf(resultId));
						}
						if (list != null && list.size() > 0) {
							dGBaiRongService.ruleResult(list);
						}
						edcBrRuleFlagSignMapper.insertSelective(edcBrRuleFlagSignDto);
						swift_number = xssPackAllInterfaceInfo.getSwift_number();
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error("loanId:" + loanId + ",百融一卡贷打包所有接口数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					status = LocalStatus.CALL_SUCCESS.getCode();
					resp.setMsg(">>>>>>>>>>>loanId:" + loanId + ",调用百融一卡贷打包所有接口,返回错误码：" + code);
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel,
					method, sTime, eTime);
		}
		saveDataQueryLog(serialNum, loanId, "", xssPackAllInterfaceInfo.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0001,
				code, status, "edc_br_data_query_log", "sys");
		
		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), json.toString(), result, channel, method,
				sTime, eTime, swift_number, "");

		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(loanId, ThirdMethodConstants.YK0001, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷打包调用");
		return resp;
	}

	@Override
	public ApiResponse<EquipmentInfor> equipmentInformationVerification(Map<String, String> map) {
		ApiResponse<EquipmentInfor> resp = new ApiResponse<EquipmentInfor>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0036")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String name = map.get("name");
		String afSwiftNumber = map.get("afSwiftNumber");
		String code="";
		Date responseDate=null;
		String status=LocalStatus.REQUEST_FAIL.getCode();
		JSONObject multipleJson = new JSONObject();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		JSONArray array = new JSONArray();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("name", name);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_cash");
		multipleJson.put("meal", "EquipmentCheck");
		EquipmentInfor equipmentInfor = new EquipmentInfor();
		String tokenId = platLogin();
		String result = "";
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>百融一卡贷设备信息核查请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>百融一卡贷设备信息核查返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					equipmentInfor = JSON.parseObject(result, EquipmentInfor.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(equipmentInfor);
					// 数据落地
					try {
						dGBaiRongService.equipmentInformationVerification(equipmentInfor, serialNum, loanId, "",mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>百融一卡贷设备信息核查数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", equipmentInfor.getSwift_number(), sTime, ThirdMethodConstants.BR0036,
				code, status, "edc_br_data_query_log", "");
		return resp;
	}

	@Override
	public ApiResponse<EquipmentSpecialList> equipmentSpecialListInfo(Map<String, String> map) {
		ApiResponse<EquipmentSpecialList> resp = new ApiResponse<EquipmentSpecialList>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0037")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String name = map.get("name");
		String afSwiftNumber = map.get("afSwiftNumber");
		JSONObject multipleJson = new JSONObject();
		EquipmentSpecialList equipmentSpecialList = new EquipmentSpecialList();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		JSONArray array = new JSONArray();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("name", name);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_cash");
		multipleJson.put("meal", "EquipmentSpecialList");
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status = LocalStatus.REQUEST_FAIL.getCode();
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>>百融一卡贷设备信息核查请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				
			}
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>>百融一卡贷设备信息核查返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					equipmentSpecialList = JSON.parseObject(result, EquipmentSpecialList.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(equipmentSpecialList);
					// 数据落地
					try {
						dGBaiRongService.equipmentSpecialListInfo(equipmentSpecialList, serialNum, loanId, "",mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>>>百融一卡贷设备信息核查数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", equipmentSpecialList.getSwift_number(), sTime, ThirdMethodConstants.BR0037,
				code, status, "edc_br_data_query_log", "");

		return resp;
	}

	@Override
	public ApiResponse<EquipmentInfo> equipmentInfo(Map<String, String> map) {
		ApiResponse resp = new ApiResponse();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.br0038")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String name = map.get("name");
		String afSwiftNumber = map.get("afSwiftNumber");
		JSONObject multipleJson = new JSONObject();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		EquipmentInfo equipmentInfo = new EquipmentInfo();
		JSONArray array = new JSONArray();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("name", name);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_cash");
		multipleJson.put("meal", "EquipmentInfo");
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status = LocalStatus.REQUEST_FAIL.getCode();
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>百融一卡贷设备信息核查请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>百融一卡贷设备信息核查返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					equipmentInfo = JSON.parseObject(result, EquipmentInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(equipmentInfo);
					// 数据落地
					try {
						dGBaiRongService.equipmentInfo(equipmentInfo, serialNum, loanId, "",mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>百融一卡贷设备信息核查数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				
			}
		}
		saveDataQueryLogNew(serialNum, loanId, "", equipmentInfo.getSwift_number(), sTime, ThirdMethodConstants.BR0038,
				code, status, "edc_br_data_query_log", "");
		return resp;
	}

	@Override
	public ApiResponse<LoanFacilityPackageInfo> loanFacilityInformationReportPack(Map<String, String> map) {
		ApiResponse<LoanFacilityPackageInfo> resp = new ApiResponse<LoanFacilityPackageInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0007")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String name = map.get("name");
		String afSwiftNumber = map.get("afSwiftNumber");
		String custIdCard = map.get("custIdCard");
		JSONObject multipleJson = new JSONObject();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		JSONArray array = new JSONArray();
		LoanFacilityPackageInfo loanFacilityPackageInfo = new LoanFacilityPackageInfo();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("id", custIdCard);
		multipleJson.put("name", name);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_lend");
		multipleJson.put("meal", "LoanEquipment,EquipmentCheck,EquipmentSpecialList,EquipmentInfo");
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>百融一卡贷借款设备信息核查请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>>百融一卡贷借款设备信息核查返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					loanFacilityPackageInfo = JSON.parseObject(result, LoanFacilityPackageInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(loanFacilityPackageInfo);
					// 数据落地
					LoanFacilityInformation loanFacilityInformation = new LoanFacilityInformation();
					EquipmentSpecialList equipmentSpecialList = new EquipmentSpecialList();
					equipmentSpecialList = loanFacilityPackageInfo.getEquipmentSpecialList();
					equipmentSpecialList.setQuery_event("antifraud_lend");
					loanFacilityInformation = loanFacilityPackageInfo.getLoanFacilityInformation();
					EquipmentInfor equipmentInfor = new EquipmentInfor();
					equipmentInfor = loanFacilityPackageInfo.getEquipmentInfor();
					equipmentInfor.setQuery_event("antifraud_lend");
					EquipmentInfo equipmentInfo = new EquipmentInfo();
					equipmentInfo = loanFacilityPackageInfo.getEquipmentInfo();
					equipmentInfo.setQuery_event("antifraud_lend");
					try {
						long id = dGBaiRongService.loanFacilityInformationReport(loanFacilityInformation, serialNum,
								loanId, mobile);
						String foreignId = String.valueOf(id);
						dGBaiRongService.equipmentSpecialListInfo(equipmentSpecialList, serialNum, loanId, foreignId,mobile);
						dGBaiRongService.equipmentInformationVerification(equipmentInfor, serialNum, loanId, foreignId,mobile);
						dGBaiRongService.equipmentInfo(equipmentInfo, serialNum, loanId, foreignId,mobile);
						// 回写注册 登录 反欺诈表
						edcBrSignequipmentMapper.updateByMobile(loanId, mobile);
						intBrRegisterEquipmentMapper.updateByMobile(loanId, mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>>>百融一卡贷借款设备信息核查数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result,
					channel, ThirdMethodConstants.YK0007, sTime, eTime);
		}
		saveDataQueryLog(serialNum, loanId, "", loanFacilityPackageInfo.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0007,
				code, status, "edc_br_data_query_log", "sys");
		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result, channel,
				ThirdMethodConstants.YK0007, sTime, eTime, loanFacilityPackageInfo.getSwift_number(), "");
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(loanId, ThirdMethodConstants.YK0007, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷借款设备信息打包");

		return resp;
	}

	@Override
	public ApiResponse<RegisterFacilityPackageInfo> registerFacilityInformationReportPack(Map<String, String> map) {
		ApiResponse<RegisterFacilityPackageInfo> resp = new ApiResponse<RegisterFacilityPackageInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0006")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String name = map.get("name");
		String afSwiftNumber = map.get("afSwiftNumber");
		JSONObject multipleJson = new JSONObject();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		RegisterFacilityPackageInfo registerFacilityPackageInfo = new RegisterFacilityPackageInfo();
		JSONArray array = new JSONArray();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("name", name);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_register");
		multipleJson.put("meal", "RegisterEquipment,EquipmentCheck,EquipmentSpecialList,EquipmentInfo");
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>百融一卡贷注册设备信息请求异常");
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>>>百融一卡贷注册设备信息返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					registerFacilityPackageInfo = JSON.parseObject(result, RegisterFacilityPackageInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(registerFacilityPackageInfo);
					RegisterFacilityInformation registerFacilityInformation = new RegisterFacilityInformation();
					EquipmentSpecialList equipmentSpecialList = new EquipmentSpecialList();
					equipmentSpecialList = registerFacilityPackageInfo.getEquipmentSpecialList();
					equipmentSpecialList.setQuery_event("antifraud_register");
					registerFacilityInformation = registerFacilityPackageInfo.getRegisterFacilityInformation();
					EquipmentInfor equipmentInfor = new EquipmentInfor();
					equipmentInfor = registerFacilityPackageInfo.getEquipmentInfor();
					equipmentInfor.setQuery_event("antifraud_register");
					EquipmentInfo equipmentInfo = new EquipmentInfo();
					equipmentInfo = registerFacilityPackageInfo.getEquipmentInfo();
					equipmentInfo.setQuery_event("antifraud_register");
					// 数据落地
					try {
						long id = dGBaiRongService.registerFacilityInformationReport(registerFacilityInformation,
								serialNum, loanId, mobile);
						String foreignId = String.valueOf(id);
						dGBaiRongService.equipmentSpecialListInfo(equipmentSpecialList, serialNum, loanId, foreignId,mobile);
						dGBaiRongService.equipmentInformationVerification(equipmentInfor, serialNum, loanId, foreignId,mobile);
						dGBaiRongService.equipmentInfo(equipmentInfo, serialNum, loanId, foreignId,mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>百融一卡贷注册设备信息数据落地失败：" ,e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(mobile, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result,
					channel, ThirdMethodConstants.YK0006, sTime, eTime);
		}
		saveDataQueryLog(mobile, mobile, "", registerFacilityPackageInfo.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0006,
				code, status, "edc_br_data_query_log", "sys");
		saveLog(mobile, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result, channel,
				ThirdMethodConstants.YK0006, sTime, eTime, registerFacilityPackageInfo.getSwift_number(), "");
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(mobile, ThirdMethodConstants.YK0006, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷注册设备信息打包");

		return resp;
	}

	@Override
	public ApiResponse<LoginFacilityPackageInfo> loginFacilityInformationReportPack(Map<String, String> map) {
		ApiResponse<LoginFacilityPackageInfo> resp = new ApiResponse<LoginFacilityPackageInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0008")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String afSwiftNumber = map.get("afSwiftNumber");
		JSONObject multipleJson = new JSONObject();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		LoginFacilityPackageInfo loginFacilityPackageInfo = new LoginFacilityPackageInfo();
		JSONArray array = new JSONArray();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_login");
		multipleJson.put("meal", "SignEquipment,EquipmentCheck,EquipmentSpecialList,EquipmentInfo");
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		if (tokenId.isEmpty() || tokenId.equals("")) {

			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {

			try {

				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>百融一卡贷登录设备信息请求异常:"+e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>百融一卡贷登录设备信息返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					loginFacilityPackageInfo = JSON.parseObject(result, LoginFacilityPackageInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(loginFacilityPackageInfo);
					LoginFacilityInformation loginFacilityInformation = new LoginFacilityInformation();
					EquipmentSpecialList equipmentSpecialList = new EquipmentSpecialList();
					equipmentSpecialList = loginFacilityPackageInfo.getEquipmentSpecialList();
					equipmentSpecialList.setQuery_event("antifraud_login");
					loginFacilityInformation = loginFacilityPackageInfo.getLoginFacilityInformation();
					EquipmentInfor equipmentInfor = new EquipmentInfor();
					equipmentInfor = loginFacilityPackageInfo.getEquipmentInfor();
					equipmentInfor.setQuery_event("antifraud_login");
					EquipmentInfo equipmentInfo = new EquipmentInfo();
					equipmentInfo = loginFacilityPackageInfo.getEquipmentInfo();
					equipmentInfo.setQuery_event("antifraud_login");
					// 数据落地
					try {
						long id = dGBaiRongService.loginFacilityInformationReport(loginFacilityInformation, serialNum,
								loanId, mobile);
						String foreignId = String.valueOf(id);
						dGBaiRongService.equipmentSpecialListInfo(equipmentSpecialList, serialNum, loanId, foreignId,mobile);
						dGBaiRongService.equipmentInformationVerification(equipmentInfor, serialNum, loanId, foreignId,mobile);
						dGBaiRongService.equipmentInfo(equipmentInfo, serialNum, loanId, foreignId,mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>百融一卡贷登录设备信息数据落地失败：" ,e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(mobile, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result,
					channel, ThirdMethodConstants.YK0008, sTime, eTime);
		}
		
		saveDataQueryLog(mobile, mobile, "", loginFacilityPackageInfo.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0008,
				code, status, "edc_br_data_query_log", "sys");
		saveLog(mobile, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result, channel,
				ThirdMethodConstants.YK0008, sTime, eTime, loginFacilityPackageInfo.getSwift_number(), "");
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(mobile, ThirdMethodConstants.YK0008, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"百融一卡贷登录设备信息打包");

		return resp;
	}

	@Override
	public ApiResponse<CurrentEquipmentPackageInfo> cashFacilityInformationReportPack(Map<String, String> map) {
		ApiResponse<CurrentEquipmentPackageInfo> resp = new ApiResponse<CurrentEquipmentPackageInfo>();
		/*
		 * 如果接口停用，直接返回（视具体情况，有的返回停用，有的返回相关值） ADD BY TUXU 2018-05-31
		 */
		if (PropertiesUtils.isTurnOffForSwitch("switch.yk0009")) {
			// RespStatus.DISABLE只有接口停用时才使用定义的这个参数，其它情况按原本的来
			resp.setCode(RespStatus.DISABLE.getCode());
			resp.setMsg(RespStatus.DISABLE.getMsg());
			return resp;
		}
		String serialNum = map.get("serialNum");
		String loanId = map.get("loanId");
		String channel = map.get("channel");
		String mobile = map.get("mobile");
		String name = map.get("name");
		String afSwiftNumber = map.get("afSwiftNumber");
		String custIdCard = map.get("custIdCard");
		JSONObject multipleJson = new JSONObject();
		Date sTime = new Date();
		ThirdProperties thirdProperties = ThirdPropertiesInitUtil.getThirdProperties();
		CurrentEquipmentPackageInfo currentEquipmentPackageInfo = new CurrentEquipmentPackageInfo();
		JSONArray array = new JSONArray();
		array.add(mobile);
		multipleJson.put("cell", array);
		multipleJson.put("name", name);
		multipleJson.put("id", custIdCard);
		multipleJson.put("af_swift_number", afSwiftNumber);
		multipleJson.put("event", "antifraud_cash");
		multipleJson.put("meal", "CashEquipment,EquipmentCheck,EquipmentSpecialList,EquipmentInfo");
		String tokenId = platLogin();
		String result = "";
		String code="";
		Date responseDate=null;
		String status="";
		if (tokenId.isEmpty() || tokenId.equals("")) {
			resp.setCode(RespStatus.REQ_ERROR.getCode());
			resp.setMsg(RespStatus.REQ_ERROR.getMsg());
		} else {
			try {
				result = BaiRongUtil.urlConnectPost(thirdProperties.getBr_oneCreditCard_packetRequestUrl(),
						"tokenid=" + tokenId + "&apiCode=" + thirdProperties.getBr_oneCreditCard_apiCode()
								+ "&jsonData=" + URLEncoder.encode(multipleJson.toString(), "utf-8") + "&checkCode="
								+ BaiRongUtil.getCheckData(multipleJson.toString(),
										thirdProperties.getBr_oneCreditCard_apiCode(), tokenId));
			} catch (Exception e) {
				MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>>>>百融一卡贷提现设备信息请求异常:",e);
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
			responseDate=new Date();
			if (StringUtils.isNotEmpty(result)) {
				MarvelsLogUtil.getInstance().info(">>>>>>>>>>>>>>>>>百融一卡贷提现设备信息返回信息:" + result);
				JSONObject resultJson = new JSONObject();
				resultJson = JSONObject.fromObject(result);
				code = resultJson.get("code").toString();
				if (code.equals("00") || code.equals("100002")) {
					if(code.equals("00")){
						status = LocalStatus.SUCCESS_WITH_DATA.getCode();
					}else{
						status = LocalStatus.SUCCESS_WITHOUT_DATA.getCode();
					}
					currentEquipmentPackageInfo = JSON.parseObject(result, CurrentEquipmentPackageInfo.class);
					resp.setCode(RespStatus.SUCCESS.getCode());
					resp.setMsg(RespStatus.SUCCESS.getMsg());
					resp.setData(currentEquipmentPackageInfo);
					CurrentEquipmentInformationReport currentEquipmentInformationReport = new CurrentEquipmentInformationReport();
					EquipmentSpecialList equipmentSpecialList = new EquipmentSpecialList();
					equipmentSpecialList = currentEquipmentPackageInfo.getEquipmentSpecialList();
					equipmentSpecialList.setQuery_event("antifraud_cash");
					currentEquipmentInformationReport = currentEquipmentPackageInfo
							.getCurrentEquipmentInformationReport();
					EquipmentInfor equipmentInfor = new EquipmentInfor();
					equipmentInfor = currentEquipmentPackageInfo.getEquipmentInfor();
					equipmentInfor.setQuery_event("antifraud_cash");
					EquipmentInfo equipmentInfo = new EquipmentInfo();
					equipmentInfo = currentEquipmentPackageInfo.getEquipmentInfo();
					equipmentInfo.setQuery_event("antifraud_cash");
					// 数据落地
					try {
						dGBaiRongService.cashFacilityInformationReport(currentEquipmentInformationReport, serialNum,
								loanId, mobile);
						dGBaiRongService.equipmentSpecialListInfo(equipmentSpecialList, serialNum, loanId, "",mobile);
						dGBaiRongService.equipmentInformationVerification(equipmentInfor, serialNum, loanId, "",mobile);
						dGBaiRongService.equipmentInfo(equipmentInfo, serialNum, loanId, "",mobile);
					} catch (Exception e) {
						MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>>>>百融一卡贷提现设备信息数据落地失败：",e);
						resp.setCode(RespStatus.DATABASE_ERROR.getCode());
						resp.setMsg(RespStatus.DATABASE_ERROR.getMsg());
						status = LocalStatus.IN_DATABASE_FAIL.getCode();
					}
				} else {
					resp.setCode(RespStatus.REQ_ERROR.getCode());
					resp.setMsg("调用百融接口,返回错误码：" + code);
					status = LocalStatus.CALL_SUCCESS.getCode();
				}
			} else {
				resp.setCode(RespStatus.REQ_ERROR.getCode());
				resp.setMsg(RespStatus.REQ_ERROR.getMsg());
				status = LocalStatus.REQUEST_FAIL.getCode();
			}
		}
		Date eTime = new Date();
		if (resp.getCode() != RespStatus.SUCCESS.getCode()) {

			saveErrorLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result,
					channel, ThirdMethodConstants.YK0009, sTime, eTime);
		}
		
		saveDataQueryLog(serialNum, loanId, "", currentEquipmentPackageInfo.getSwift_number(), sTime, responseDate, ThirdMethodConstants.YK0009,
				code, status, "edc_br_data_query_log", "sys");
		saveLog(serialNum, Integer.toString(resp.getCode()), resp.getMsg(), multipleJson.toString(), result, channel,
				ThirdMethodConstants.YK0009, sTime, eTime, currentEquipmentPackageInfo.getSwift_number(), "");
		String resultLog = "";
		if (resp.getCode() == RespStatus.SUCCESS.getCode() || resp.getCode() == RespStatus.DATABASE_ERROR.getCode()) {
			resultLog = "1";
		} else if (resp.getCode() == RespStatus.NODATA.getCode()) {
			resultLog = "0";
		} else {
			resultLog = "-1";
		}
		saveCallCountLog(mobile, ThirdMethodConstants.YK0009, resultLog, ThirdProductChannelConstant.BAIRONG.getCode(),
				"设备特殊名单");

		return resp;
	}

}
